{include file="public/header"/}
<script src="{__PUBLIC_PATH}/common/js/admin_jquery-ui.min.js?t={php}echo time();{/php}"></script>
<script src="{__PUBLIC_PATH}/common/plugins/Ueditor/ueditor.config.js?t={php}echo time();{/php}"></script>
<script src="{__PUBLIC_PATH}/common/plugins/Ueditor/ueditor.all.min.js?t={php}echo time();{/php}"></script>
<script src="{__PUBLIC_PATH}/common/plugins/Ueditor/lang/zh-cn/zh-cn.js?t={php}echo time();{/php}"></script>
<!--<script src="{__PUBLIC_PATH}/common/plugins/wxeditor/ueditor/ueditor.all.js?t={php}echo time();{/php}"></script>
<script src="{__PUBLIC_PATH}/common/plugins/wxeditor/wxeditor.js?t={php}echo time();{/php}"></script>-->
</head>
<body>
<style>
.layui-form-selected dl{z-index: 999999 !important;}
</style>
<form class="layui-form" id="pcfcms-form" onsubmit="return false;">
    <div class="layui-fluid pd83" id="LAY-component-layer-list">
        <div class="layui-card">
            <div class="layui-tab layui-tab-card hideshadow">
              <ul class="layui-tab-title">
                <li class="layui-this">常规选项</li>
                <li>其它选项</li>
              </ul>
              <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><b class="pcfts">*</b> 主题</label>
                        <div class="layui-input-inline pcfcms_layui-input-inline">
                            <input type="text" name="title" id="title"  lay-verify="required" value="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><b class="pcfts">*</b> 所属栏目</label>
                        <div class="layui-input-inline">
                            <select name="typeid" id="typeid" lay-verify="check_typeid">
                                <option value="0">请选择栏目</option>
                                {$arctype_html|raw}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">文档属性</label>
                        <div class="layui-input-block">
                            <input type="checkbox" value="1" name="is_head" lay-skin="primary" title="头条[h]">
                            <input type="checkbox" value="1" name="is_recom" lay-skin="primary" title="推荐[c]">
                            <input type="checkbox" value="1" name="is_special" lay-skin="primary" title="特推[a]" >
                            <input type="checkbox" value="1" name="is_b" lay-skin="primary" title="加粗[b]" >
                            <input type="checkbox" value="1" name="is_litpic" lay-skin="primary" title="图片[p]">
                            <input type="checkbox" value="1" name="is_jump"  lay-skin="primary" lay-filter="is_jump" title="跳转[j]">
                        </div>
                    </div>
                    <div class="layui-form-item none" id="jump_div">
                        <label class="layui-form-label">跳转网址</label>
                        <div class="layui-input-inline pcfcms_layui-input-inline">
                            <input type="text" name="jumplinks" id="jumplinks" value="" class="layui-input"  placeholder="http://"><p>请输入完整的URL网址（包含http或https），设置后访问该条信息将直接跳转到设置的网址</p>
                        </div>
                    </div>

                    <div class="layui-form-item">
                      <label class="layui-form-label">缩略图</label>
                      <div class="layui-input-inline auto">
                        <ul class="layout">
                          <li>
                            <input name="litpic" id="litpic" placeholder="图片地址" value="" class="layui-input inp inp_logo">
                            <img id="img_litpic" src="{:get_default_pic()}" class="none">
                          </li>
                          <li style="margin-top:3px;margin-left:5px;">
                            <div class="layui-btn-group">
                            <input type="button" value="上传图片" class="layui-btn layui-btn-sm pcfcms-upload" lay-data="{number:1,pcf_inputId:'litpic',pcf_savepath:'allimg'}">
                            <input type="button" value="选择图片" class="layui-btn layui-btn-sm" onClick="GetPictureFolder(1,'litpic');">
                            <input type="button" value="预览" class="layui-btn layui-btn-sm" onclick="BigImages($('#img_litpic').attr('src'));">
                            <input type="button" value="清除" class="layui-btn layui-btn-sm layui-btn-warm" data-inputid="litpic" onclick="DelImages(this);">
                            </div>
                          </li>
                        </ul>
                      </div>
                    </div>
                    
                    {include file="field/addonextitem"/}
                </div>
                <div class="layui-tab-item">
                    <div class="layui-form-item">
                        <label class="layui-form-label">SEO标题</label>
                        <div class="layui-input-inline pcfcms_layui-input-inline">
                            <input type="text" name="seo_title" id="seo_title" value="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">SEO关键词</label>
                        <div class="layui-input-inline pcfcms_layui-input-inline">
                            <input type="text" name="seo_keywords" id="seo_keywords" value="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">SEO描述</label>
                        <div class="layui-input-inline pcfcms_layui-input-inline">
                            <textarea name="seo_description" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">作者</label>
                        <div class="layui-input-inline">
                            <input type="text" value="{$admin_info.pen_name|default='小编'}" name="author" id="author" class="layui-input">
                        </div>
                        <div class="layui-input-inline layadmin-layer-demo">
                            <a class="layui-btn layui-btn-sm" data-type="author_mark">设置</a>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">浏览量</label>
                        <div class="layui-input-inline">
                            <input type="text" value="{php}echo mt_rand(100, 300);{/php}" name="click" id="click" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">阅读权限</label>
                        <div class="layui-input-inline">
                            <select name="arcrank" id="arcrank">
                                {volist name="arcrank_list" id="vo"}
                                <option value="{$vo.rank}">{$vo.name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">发布时间</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="add_time" name="add_time" value="{php}echo date('Y-m-d H:i:s'){/php}" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">文档模板</label>
                        <div class="layui-input-inline">
                            <select name="tempview" id="tempview">
                                {volist name='$templateList' id='vo'}
                                <option value="{$vo}" {eq name='$vo' value='$tempview'}selected{/eq}>{$vo}</option>
                                {/volist}
                            </select>
                            <input type="hidden" name="type_tempview" value="{$tempview}"/>
                        </div>
                    </div>
                </div>
                <div style="pcfclear"></div>
              </div>
            </div>
        </div>
    </div>
    <div class="submit-info text-center">
        <button class="layui-btn" lay-submit lay-filter="formSubmit">确认提交</button>
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
    </div>
</form>
{include file="public/footer"/}
<script>
    layui.use(['layer', 'form', 'element'], function () {
        var $ = layui.$,
        element = layui.element,
        layer = layui.layer,
        form = layui.form;
        element.render();

        // 选中跳转链接
        form.on('checkbox(is_jump)',function (obj) {
            if ($(this).is(':checked')) {
                $('#jump_div').show();
            } else {
                $('#jump_div').hide();
            }
        });

        form.verify({
            check_typeid: function(value, item){
                if(0 == value){return '请选择所属栏目';}
            }
        });

        // 自定义字段的复选框
        form.on('checkbox(addonFieldExt)', function(data){
            try{
                var callback = data.elem.attributes['data-callback']['nodeValue'];
                eval(callback+"()");
            }catch(e){}
        });

        $(document).on("click","#LAY-component-layer-list .layadmin-layer-demo .layui-btn",function(){
          var type = $(this).data('type');
          active[type] && active[type].call(this);
        });

        // 触发事件
        var active = {
            author_mark:function (){set_author();}//设置作者
        };
        laydate.render({elem: '#add_time',type: 'datetime'});

        //监听提交
        form.on('submit(formSubmit)', function(data){
            ueditorHandle();
            layer.msg('正在处理请勿刷新页面', {icon: 16,shade: 0.01,time:3600000});
            var pcfdata = $("#pcfcms-form").serialize();
            $.ajax({
                type : 'post',
                url : "{:url('/product/add')}",
                data : pcfdata,
                dataType : 'json',
                success : function(res){
                    layer.closeAll();
                    if(res.status){
                        parent.window.location.href = res.url;
                    }else{
                        layer.msg(res.msg, {icon: 2, time: 1000});
                    }
                },
                error: function(e){
                    layer.closeAll();
                    layer.msg("未知错误，操作中断！", {icon: 2, time: 1000});
                }
            });
        });
        
    });

    // 设置作者
    function set_author(){
        layer.prompt({title:'<font color="red">设置作者默认名称</font>'},
            function(val, index){
                var admin_id = "{$admin_info.admin_id}";
                $.ajax({
                    url: "{:url('/ajax/ajax_setfield')}",
                    type: 'POST',
                    dataType: 'JSON',
                    data: {id_name:'admin_id',id_value:admin_id,field:'pen_name',value:val},
                    success: function(res){
                        if (res.status) {
                            $('#author').val(val);
                            layer.msg(res.msg, {icon: 1, time:1000});
                        } else {
                            layer.msg(res.msg, {icon: 2, time: 1000});
                            return false;
                        }
                    },
                    error: function(e){
                        layer.msg("未知错误，操作中断！", {icon: 2, time: 1000});
                        return false;
                    }
                });
                layer.close(index);
            }
        );
    }

</script>

